package com.leyou.search.mq;

import com.leyou.common.constants.MQConstants;
import com.leyou.search.service.SearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName : ItemListener  //类名
 * @Description :   //描述
 * @Author : qingfeng  //作者
 * @Date: 2020-09-24 19:36  //时间
 */
@Component
public class ItemListener {
    @Autowired
    private SearchService searchService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MQConstants.QueueConstants.SEARCH_ITEM_UP, durable = "true"),
            exchange = @Exchange(name = MQConstants.ExchangeConstants.ITEM_EXCHANGE_NAME, type = ExchangeTypes.TOPIC),
            key = MQConstants.RoutingKeyConstants.ITEM_UP_KEY
    ))
    public void listenItemDown(Long spuId) {
        if (spuId != null) {
            searchService.deleteGoodsById(spuId);
        }
    }
}
